// pages/NoAssociated/NoAssociated.js
var request = require("../../utils/request.js")
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    type: '',
    tid: '',
    info: "",
    info1: "",
    s: "0",
    m: '0',
  },
  //关联成员
  Relation: function () {
    if (this.data.tid == '') {
      this.toastDialog.showDialog({ code: 'warinning', message: '请选择要关联的报告', totastType: 'black', timeout: true });
      return false
    } else {
      wx.navigateTo({
        url: '../report/report?tid=' + this.data.tid + '&type=' + this.data.type,
      })
    }

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.toastDialog = this.selectComponent("#toastDialog");//此处id和页面的 wxml中的id一致
    // this.queryUnBind()
    wx.showShareMenu({ menus: ['shareAppMessage', 'shareTimeline']})
  },
/**
 * 用户点击右上角分享
 */
onShareAppMessage (res) {
  return {
    title: '迪佳极视',
    path: 'pages/index/index',
    // imageUrl:'这个是显示的图片，不写就默认当前页面的截图',
    success: function (shareTickets) {
      console.info(shareTickets + '成功');
      // 转发成功
    },
    fail: function (res) {
      console.log(res + '失败');
      // 转发失败
    },
    complete:function(res){
      // 不管成功失败都会执行
    }
  }
},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    // this.queryUnBind()

  },
  /**
    * 生命周期函数--监听页面显示
    */
  onShow: function () {
    this.queryUnBind()

  },
  queryUnBind: function () {
    var that = this;
    that.toastDialog.showDialog({ code: 'loading', message: '加载中', timeout: false }); //loading 加载框
    request.postData('xcx/unBindAll', {}, function (res) {

      that.toastDialog.hideDialog(); //关闭loading提示框
      if (res.code == 0) {
        if (res.list.length != 0) {
          res.list.forEach(function (v, i) {
            //console.log(v);
            v.checked = false;
          })
          that.setData({
            list: res.list
          })
        } else {
          that.setData({
            info: "暂无数据~",
            s: "1",
            m: '1'
          })
        }

      } else {
        that.toastDialog.showDialog({ code: res.code, message: res.message, timeout: true });
      }
    }, function (res) {
      that.toastDialog.showDialog({ code: res.code, message: res.message, timeout: true });
    });
  },
  //chekcbox
  checkboxChange: function (e) {
    var that = this
    let arr = that.data.list
    console.log(e.currentTarget.dataset.item)
    arr.forEach(function (v, i) {
      if (v.id == e.currentTarget.dataset.item.id && v.type == e.currentTarget.dataset.item.type) {
        v.checked = !v.checked
        e.currentTarget.dataset.item.checked = !e.currentTarget.dataset.item.checked
      } else {
        v.checked = false
      }
    })
    if (e.currentTarget.dataset.item.checked) {
      that.setData({
        tid: e.currentTarget.dataset.item.id,
        type: e.currentTarget.dataset.item.type,
        list: arr
      })
    } else {
      that.setData({
        tid: '',
        type: '',
        list: arr

      })
    }
    console.log(that.data)
  }
})